package Thread;

public class ThreadDemo6 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            //currentThread 获取当前线程的实例
            //此处currentThread获取到的就是t
            //isInterrupted就是t对象里面自带的标志位
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello t1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        });
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //把t内部的标志位设置为true
        t.interrupt();
    }
}
